﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.Mvc;
using System.Dynamic;
using Enter.Services.Mail;
using Enter.Mvc.Base.Controllers;
using Enter.Mvc.Mall.Model;
using Enter.Mvc.Base.ActionFilters;
using Enter.Common;
using System.Reflection;
using Enter.Services.DataCache;
using System.Data;
using Enter.Common.statics;

namespace Enter.Mvc.Mall.Controllers
{
    public class HomeController : BaseControllers
    {
        private readonly ICache icache;
        private readonly IMail imail;

        public HomeController(ICache cache, IMail mail)
        {
            this.icache = cache;
            this.imail = mail;
        }

        public ActionResult Index()
        {
            dynamic design = new ExpandoObject();
            design.id = imail.GetBaseById(0);


            string key = CustomKey.Build(MethodInfo.GetCurrentMethod(),new object[]{ 1 });
            DataTable ta = icache.Get<DataTable>(key);
            if (ta == null)
            {
                ta = imail.GetBaseTableById(1);
				
                icache.Put(key, ta);
            }
            DataTable dy = ta;

            return View(design);
        }

        [CacheAction]
        public DemoModel User()
        {
            DemoModel demo = new DemoModel();
            demo.id = 1;
            demo.money = 2;
            demo.title = "测试";
            return demo;
        }
    }
}
